package xyz.ddlnt.user.usr.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.servlet.http.HttpServletRequest;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.web.bind.annotation.*;
import xyz.ddlnt.commonutil.constant.MqConstants;
import xyz.ddlnt.commonutil.result.Result;
import xyz.ddlnt.commonutil.util.HttpUtils;
import xyz.ddlnt.model.dto.PageDTO;
import xyz.ddlnt.model.dto.UserContentInteractionDTO;
import xyz.ddlnt.model.vo.PostRecordVO;
import xyz.ddlnt.serviceusrclient.client.PostHistoryRecordFeignClient;

import java.util.List;

/**
 * @author ZZULI_SE 210910
 * @data 2025/5/25 21:02
 */
@Slf4j
@Tag(name = "帖子浏览记录接口测试")
@RequestMapping("/post_history_record")
@RestController
public class PostHistoryRecordController {
    @Resource
    private RabbitTemplate rabbitTemplate;
    @Resource
    private PostHistoryRecordFeignClient postHistoryRecordFeignClient;

    @Operation(summary = "添加帖子浏览记录")
    @PostMapping("/addHistoryRecord/{id}")
    public void addHistoryRecord(@PathVariable Long id, HttpServletRequest request) {
        UserContentInteractionDTO userContentInteractionDTO = UserContentInteractionDTO.builder()
                .userId(HttpUtils.getId(request))
                .id(id)
                .build();
        rabbitTemplate.convertAndSend(MqConstants.USR_POST_HISTORY_RECORD, MqConstants.POST_HISTORY_RECORD_PLUS_ONE, userContentInteractionDTO);
    }


    @Operation(summary = "获取帖子浏览历史")
    @PostMapping("/getPostHistoryRecordList")
    Result<List<PostRecordVO>> getPostHistoryRecordList(@RequestBody PageDTO pageDTO, HttpServletRequest request) {
        pageDTO.setId(HttpUtils.getId(request));
        return postHistoryRecordFeignClient.getPostHistoryRecordList(pageDTO);
    }
    @Operation(summary = "删除帖子浏览记录")
    @DeleteMapping("/remove/{id}")
    Result<Boolean> removeById(@PathVariable Long id) {
        return postHistoryRecordFeignClient.removeById(id);
    }
}
